//
//  GameLayer.cpp
//  Birds
//
//  Created by Denveryee on 14-2-10.
//
//

#include "GameLayer.h"
#include "Bird.h"
#include "SimpleAudioEngine.h"

USING_NS_CC;

bool GameLayer::init(){

    if ( !CCLayer::init() )
    {
        return false;
    }
    
    // ask director the window size
    size = CCDirector::sharedDirector()->getWinSize();
    
    _birds = new CCArray();
    _birds->retain();
    
    CCSprite* bg = CCSprite::create("bg.jpg");
    bg->setPosition(ccp(size.width/2, size.height/2));
    this->addChild(bg, -3);
    
    CCSprite* tree1 = CCSprite::create("m2.png");
    tree1->setAnchorPoint(ccp(0, 1));
    tree1->setPosition(ccp(27, 426));
    this->addChild(tree1, -2);
    
    CCSprite* tree2 = CCSprite::create("m1.png");
    tree2->setAnchorPoint(ccp(1, 1));
    tree2->setPosition(ccp(635, 351+309-218));
    this->addChild(tree2, -2);
    
    CCSprite* grass = CCSprite::create("grass.png");
    grass->setAnchorPoint(ccp(0.5, 1));
    grass->setPosition(ccp(size.width/2, 289));
    this->addChild(grass, -1);

    //柱子1
    sprPipe1 = CCSprite::create("pipe1.png");
    sprPipe1->setPosition( ccp(506, 1169) );
    this->addChild(sprPipe1, 0);
    //柱子2
    sprPipe2 = CCSprite::create("pipe2.png");
    sprPipe2->setPosition( ccp(506, 253) );
    this->addChild(sprPipe2, 0);
    
    CCSprite* ground = CCSprite::create("ground.png");
    ground->setAnchorPoint(ccp(0.5f, 0));
    ground->setPosition(ccp(size.width/2, 0));
    this->addChild(ground, 1);
    
    CCSprite *cloud1 = CCSprite::create("cloud1.png");
    CCSprite *cloud2 = CCSprite::create("cloud2.png");
    
    cloud1->setPosition(ccp(size.width-200, 1027));
    this->addChild(cloud1, -1);
    cloud1->runAction(CCMoveBy::create(45, ccp(-1000, 0)));
    
    cloud2->setPosition(ccp(size.width/2+100, 795));
    this->addChild(cloud2, -1);
    cloud2->runAction(CCMoveBy::create(40, ccp(-1000, 0)));
    
    //得分
    labelScore = CCLabelAtlas::create("0123456789", "best_score_num.png", 76, 110, '0');
    labelScore->setAnchorPoint(ccp(0.5, 1));
    labelScore->setPosition(ccp(size.width/2, 987));
    this->addChild(labelScore);
    labelScore->setString("0");
    
    //碰撞检测
    this->scheduleUpdate();
    //定时生成飞猪
    this->schedule(schedule_selector(GameLayer::createBird), 1);
    //定时生成云彩
    this->schedule(schedule_selector(GameLayer::createCloud), 20);

    
    /************************bloof*********************/
     //blood
     CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("blood.png");
     
     // manually add frames to the frame cache
     frame0 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*0, 138*0, 325, 138));
     CCSpriteFrame *frame1 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*1, 138*0, 325, 138));
     CCSpriteFrame *frame2 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*2, 138*0, 325, 138));
     CCSpriteFrame *frame3 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*3, 138*0, 325, 138));
     CCSpriteFrame *frame4 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*4, 138*0, 325, 138));
     CCSpriteFrame *frame5 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*0, 138*1, 325, 138));
     CCSpriteFrame *frame6 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*1, 138*1, 325, 138));
     CCSpriteFrame *frame7 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*2, 138*1, 325, 138));
     CCSpriteFrame *frame8 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*3, 138*1, 325, 138));
     CCSpriteFrame *frame9 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*4, 138*1, 325, 138));
     CCSpriteFrame *frame10 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*0, 138*2, 325, 138));
     CCSpriteFrame *frame11 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*1, 138*2, 325, 138));
     CCSpriteFrame *frame12 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*2, 138*2, 325, 138));
     CCSpriteFrame *frame13 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*3, 138*2, 325, 138));
     CCSpriteFrame *frame14 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*4, 138*2, 325, 138));
     CCSpriteFrame *frame15 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*0, 138*3, 325, 138));
     CCSpriteFrame *frame16 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*1, 138*3, 325, 138));
     CCSpriteFrame *frame17 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*2, 138*3, 325, 138));
     CCSpriteFrame *frame18 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*3, 138*3, 325, 138));
     CCSpriteFrame *frame19 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*4, 138*3, 325, 138));
     CCSpriteFrame *frame20 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*0, 138*4, 325, 138));
     CCSpriteFrame *frame21 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*1, 138*4, 325, 138));
     CCSpriteFrame *frame22 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*2, 138*4, 325, 138));
     CCSpriteFrame *frame23 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*3, 138*4, 325, 138));
     CCSpriteFrame *frame24 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*4, 138*4, 325, 138));
     CCSpriteFrame *frame25 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*0, 138*5, 325, 138));
     CCSpriteFrame *frame26 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*1, 138*5, 325, 138));
     CCSpriteFrame *frame27 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*2, 138*5, 325, 138));
     CCSpriteFrame *frame28 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*3, 138*5, 325, 138));
     CCSpriteFrame *frame29 = CCSpriteFrame::createWithTexture(texture, CCRectMake(325*4, 138*5, 325, 138));
    
    frame0->retain();
    
     animFrames = CCArray::createWithCapacity(30);
     animFrames->addObject(frame0);
     animFrames->addObject(frame1);
     animFrames->addObject(frame2);
     animFrames->addObject(frame3);
     animFrames->addObject(frame4);
     animFrames->addObject(frame5);
     animFrames->addObject(frame6);
     animFrames->addObject(frame7);
     animFrames->addObject(frame8);
     animFrames->addObject(frame9);
     animFrames->addObject(frame10);
     animFrames->addObject(frame11);
     animFrames->addObject(frame12);
     animFrames->addObject(frame13);
     animFrames->addObject(frame14);
     animFrames->addObject(frame15);
     animFrames->addObject(frame16);
     animFrames->addObject(frame17);
     animFrames->addObject(frame18);
     animFrames->addObject(frame19);
     animFrames->addObject(frame20);
     animFrames->addObject(frame21);
     animFrames->addObject(frame22);
     animFrames->addObject(frame23);
     animFrames->addObject(frame24);
     animFrames->addObject(frame25);
     animFrames->addObject(frame26);
     animFrames->addObject(frame27);
     animFrames->addObject(frame28);
     animFrames->addObject(frame29);
    
    animFrames->retain();
    
    blood = CCSprite::createWithSpriteFrame(frame29);
    blood->setScale(6);
    blood->setPosition( ccp(496, 331) );
    this->addChild(blood, 1);
    
    /*************************blood*******************************/
    
    return true;
}

GameLayer::GameLayer(void){
    pipeClose = false;
    //游戏得分；
    score = 0;
    gameOverCheck = false;
    cheer1 = false;
    cheer2 = false;
    cheer3 = false;
    newRecord = false;
}

GameLayer::~GameLayer(void){
  CC_SAFE_RELEASE_NULL(_birds);
}

void GameLayer::onEnter(){
    
    CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0,false);
    CCLayer::onEnter();
}

void GameLayer::onExit(){
    
    CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
    CCLayer::onExit();
}

/*
 屏幕点击事件
 */
bool GameLayer::ccTouchBegan(CCTouch* touch, CCEvent* event)
{
    if(pipeClose || gameOverCheck){
        ;
    }else{
        pipeClose = true;
        CCActionInterval*  actionBy1 = CCMoveBy::create(0.1f, ccp(0, -168));
        CCActionInterval*  actionByBack1 = actionBy1->reverse();
        
        CCFiniteTimeAction*  action = CCSequence::create(
                                                         CCSequence::create(actionBy1,
                                                                            CCSequence::create(
                                                                                               CCSpawn::create(
                                                                                                               CCMoveBy::create(0.05f, ccp(10,2)),
                                                                                                               CCCallFunc::create(this, callfunc_selector(GameLayer::pipeCloseSound)),
                                                                                                               NULL
                                                                                                               ),
                                                                                               
                                                                                               CCMoveBy::create(0.05f, ccp(-10,-2)),
                                                                                               NULL),
                                                                            actionByBack1, NULL),
                                                         
                                                         CCCallFunc::create(this, callfunc_selector(GameLayer::pipeCloseCallback)),
                                                         NULL);
        
        sprPipe1->runAction(action);
        
        CCActionInterval*  actionBy2 = CCMoveBy::create(0.1f, ccp(0, 168));
        CCActionInterval*  actionByBack2 = actionBy2->reverse();
        sprPipe2->runAction( CCSequence::create(actionBy2,
                                                CCSequence::create(
                                                                   CCMoveBy::create(0.05f, ccp(10,2)),
                                                                   CCMoveBy::create(0.05f, ccp(-10,-2)),
                                                                   NULL),
                                                actionByBack2, NULL));
    }
    return true;
}

void GameLayer::ccTouchMoved(CCTouch* touch, CCEvent* event){

}

void GameLayer::ccTouchEnded(CCTouch* touch, CCEvent* event){

}

void GameLayer::update(float dt)
{
    CCObject* bird;
    
    // cocos2d定义的宏，提供方便的只读遍历CCARRAY写法
    CCARRAY_FOREACH(_birds, bird)
    {
        Bird* temp = (Bird*)bird;
        //游戏结束判断
        if(temp->flyBird->getPosition().x > 600 && !gameOverCheck){
            gameOverCheck = true;
            
            CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("start.mp3");
            //gameover
            unscheduleAllSelectors();
            
            CCObject* stopB;
            CCARRAY_FOREACH(_birds, stopB){
                Bird* temp = (Bird*)stopB;
                temp->flyBird->pauseSchedulerAndActions();
            }
            gameOver();
            
        }else{
            if(!temp->birdDying){
                
                CCRect pRect = CCRect(temp->flyBird->getPosition().x-82/2,
                                      temp->flyBird->getPosition().y-80/2,
                                      82,
                                      80);
                
                CCRect tRect1 = CCRect(sprPipe1->getPosition().x-126/2,
                                       sprPipe1->getPosition().y-584/2,
                                       126,
                                       584);
                
                CCRect tRect2 = CCRect(sprPipe2->getPosition().x-126/2,
                                       sprPipe2->getPosition().y-584/2,
                                       126,
                                       584);
                
                // 碰撞测试
                if( pRect.intersectsRect( tRect1 ) || pRect.intersectsRect( tRect2 ))
                {
                    if(temp->birdKick){
                        ;
                    }else if(temp->birdDying){
                        ;
                    }else{
                        if(temp->flyBird->getPosition().x >= sprPipe1->getPosition().x - 126/2 &&
                           temp->flyBird->getPosition().x <= sprPipe1->getPosition().x + 126/2){
                            //dying
                            temp->birdDying = true;
                            
                            temp->flyBird->stopAllActions();

                            temp->flyBird->runAction(CCSequence::create(
                                                                        CCSpawn::create(
                                                                                        CCMoveTo::create(0.1, ccp(496, 701)),
                                                                                        CCScaleBy::create(0.1f, 2.0f, 0.1f),                                                                                        NULL),
                                                                        CCDelayTime::create(0.1),
                                                                        CCCallFuncND::create(this, callfuncND_selector(GameLayer::removeBird), (void*)temp),
                                                                        NULL));
                            
                            CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.02);
                            CCAnimate *animate = CCAnimate::create(animation);
                            CCActionInterval* bloodSeq = CCSequence::create( animate,
                                                                            CCFlipX::create(false),
                                                                            NULL);

                            blood->runAction(bloodSeq);
                            
                            CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("squish1.wav");
                            //CocosDenshion::SimpleAudioEngine::sharedEngine()->unloadEffect("squish1.wav");
                            
                            //显示得分
                            score+=temp->killScore;
                            char string[12] = {0};
                            sprintf(string, "%d", score);
                            labelScore->setString(string);
                            
                            if(score >= 100 && !cheer1){
                                CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("cheer1.mp3");
                                cheer1 = true;
                            }
                            if(score >= 200 && !cheer2){
                                CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("cheer2.mp3");
                                cheer2 = true;
                            }
                            if(score >= 300 && !cheer3){
                                CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("cheer3.mp3");
                                cheer3 = true;
                            }
                        }else if(temp->flyBird->getPosition().x > sprPipe1->getPosition().x + 126/2){
                            temp->kickFront();
                            //game over
                        }else if(temp->flyBird->getPosition().x < sprPipe1->getPosition().x - 126/2){
                            temp->kickBack();
                        }else{
                            ;
                        }
                    }
                }
            }

        }
        
    }
}

void GameLayer::removeBird(CCNode* pSender, void* data)
{
    Bird *temp = (Bird*)data;
    this->removeChild(temp->flyBird);
    _birds->removeObject(temp);
}

void GameLayer::pipeCloseSound(){
    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("floor.mp3");
}

void GameLayer::pipeCloseCallback()
{
    pipeClose = false;
}

void GameLayer::createBird(float dt)
{
    int num = rand()%3+1;
    for(int i=0; i<num; i++){
        Bird* bird = Bird::create();
        bird->createFlyBird(score);
        this->addChild(bird->flyBird);
        _birds->addObject(bird);
    }
}

void GameLayer::createCloud(float dt)
{
    CCSprite *cloud1, *cloud2;
    switch (rand()%4) {
        case 0:
            cloud1 = CCSprite::create("cloud1.png");
            cloud2 = CCSprite::create("cloud2.png");
            break;
        case 1:
            cloud1 = CCSprite::create("cloud2.png");
            cloud2 = CCSprite::create("cloud3.png");
            break;
        case 2:
            cloud1 = CCSprite::create("cloud3.png");
            cloud2 = CCSprite::create("cloud4.png");
            break;
        case 3:
            cloud1 = CCSprite::create("cloud4.png");
            cloud2 = CCSprite::create("cloud1.png");
            break;
        default:
            cloud1 = CCSprite::create("cloud1.png");
            cloud2 = CCSprite::create("cloud2.png");
            break;
    }
    
    cloud1->setPosition(ccp(700+rand()%200, 827+rand()%200));
    this->addChild(cloud1, -1);
    cloud1->runAction(CCMoveBy::create(35, ccp(-1000, 0)));
    
    cloud2->setPosition(ccp(700+rand()%100, 695+rand()%100));
    this->addChild(cloud2, -1);
    cloud2->runAction(CCMoveBy::create(30, ccp(-1000, 0)));

}

void GameLayer::menuEPlayCallback(){
    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("click.mp3");
    CCScene *scene = CCScene::create();
    scene->addChild(GameLayer::create());
    CCDirector::sharedDirector()->replaceScene( CCTransitionFade::create(1, scene) );
}

void GameLayer::menuEShareCallback(){
    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("click.mp3");
    CCRenderTexture* in_texture = CCRenderTexture::create(size.width, size.height, kCCTexture2DPixelFormat_RGBA8888);
    in_texture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) );
    in_texture->setPosition( ccp(size.width/2, size.height/2) );
    in_texture->setAnchorPoint( ccp(0.5f,0.5f) );
    
    in_texture->begin();
    this->visit();
    in_texture->end();
    in_texture->saveToFile("screenshot.png", kCCImageFormatPNG);
    /*
     CCLOG("%s", CCFileUtils::sharedFileUtils()->getWritablePath().c_str());
     
     CCSprite *aaa = CCSprite::create((CCFileUtils::sharedFileUtils()->getWritablePath()+"screenshot.png").c_str());
     aaa->setAnchorPoint(ccp(0, 0));
     aaa->setPosition(ccp(size.width/2, size.height/2));
     this->addChild(aaa);*/
}

void GameLayer::gameOver(){
    //游戏结束文字
    CCSprite *gameOver = CCSprite::create("gameover.png");
    gameOver->setAnchorPoint(ccp(0.5, 1));
    gameOver->setPosition(ccp(size.width/2, 987));
    gameOver->setScale(0.01f);
    this->addChild(gameOver);
    
    CCActionInterval *small = CCScaleTo::create(1, 0.01);
    labelScore->runAction(CCEaseElasticOut::create(small));
    
    CCActionInterval *bigger = CCScaleTo::create(1, 1);
    gameOver->runAction(CCSequence::create(CCDelayTime::create(0.8),
                                           CCEaseElasticOut::create(bigger),
                                           NULL)
                        );
    
    //得分牌子
    endBgLayer = CCLayer::create();
    this->addChild(endBgLayer, 2);
    
    CCSprite *scoreBg = CCSprite::create("score_bg.png");
    scoreBg->setPosition(ccp(size.width/2-650, 772));
    scoreBg->setAnchorPoint(ccp(0.5, 1));
    endBgLayer->addChild(scoreBg);
    
    //本轮得分
    char string[12] = {0};
    sprintf(string, "%d", score);
    CCLabelAtlas *labelScore = CCLabelAtlas::create("0123456789", "score_num.png", 51, 67, '0');
    labelScore->setAnchorPoint(ccp(1, 0));
    labelScore->setPosition(ccp(499-650, 591));
    endBgLayer->addChild(labelScore);
    labelScore->setString(string);
    
    //保存最高纪录
    int heightScore = CCUserDefault::sharedUserDefault()->getIntegerForKey("heightScore");
    if(score > heightScore){
        heightScore = score;
        CCUserDefault::sharedUserDefault()->setIntegerForKey("heightScore", heightScore);
        
        CCSprite *newImage = CCSprite::create("new.png");
        newImage->setPosition(ccp(365-650, 575));
        newImage->setScale(2);
        endBgLayer->addChild(newImage);
        
    }
    
    CCLabelAtlas *labelBScore = CCLabelAtlas::create("0123456789", "score_num.png", 51, 67, '0');
    labelBScore->setAnchorPoint(ccp(1, 0));
    labelBScore->setPosition(ccp(499-650, 459));
    endBgLayer->addChild(labelBScore);
    
    char stringH[12] = {0};
    sprintf(stringH, "%d", heightScore);
    labelBScore->setString(stringH);
    
    CCFiniteTimeAction* endBgAction = CCSequence::create(CCDelayTime::create(0.3),
                                                         CCEaseElasticOut::create(CCMoveBy::create(1, ccp(650, 0))),
                                                         CCCallFuncN::create(this, callfuncN_selector(GameLayer::gameOverAction)),
                                                         NULL);
    
    endBgLayer->runAction(endBgAction);
    
    
    //按钮
    CCMenuItem* itemPlay = CCMenuItemImage::create("play.png", "play.png", this, menu_selector(GameLayer::menuEPlayCallback));
    itemPlay->setPosition(ccp(30-95, 380));
    itemPlay->setScale(0.01f);
    itemPlay->setAnchorPoint(ccp(0, 1));
    
    CCAction *bigger2 = CCScaleTo::create(1, 1);
    
    itemPlay->runAction(
                        CCSequence::create(CCDelayTime::create(1.6),
                                           CCSpawn::create(CCEaseElasticOut::create((CCActionInterval*)bigger2),
                                                           CCCallFunc::create(this, callfunc_selector(GameLayer::buttonM)),
                                                           NULL),
                                           
                                           NULL)
                        );
    
    itemShare = CCMenuItemImage::create("share.png", "share.png", this, menu_selector(GameLayer::menuEShareCallback));
    itemShare->setPosition(ccp(345-55, 380));
    itemShare->setScale(0.01f);
    itemShare->setAnchorPoint(ccp(0, 1));
    
    CCActionInterval*  bigger1 = CCScaleBy::create(1, 100);
    
    itemShare->runAction(CCSequence::create(CCDelayTime::create(2.1),
                                            
                                            CCSpawn::create(CCEaseElasticOut::create(bigger1),
                                                            CCCallFunc::create(this, callfunc_selector(GameLayer::buttonM)),
                                                            NULL),
                                            CCCallFunc::create(this, callfunc_selector(GameLayer::shareAction)),
                                            NULL)
                         );
    
    CCMenu* menuPlay = CCMenu::create(itemPlay, itemShare, NULL);
    menuPlay->setPosition(CCPointZero);
    this->addChild(menuPlay, 1);
}


void GameLayer::gameOverAction(CCNode* pSender){
    CCLOG("Tell Me Why");
    
    CCSprite *metal;
    
    
    if(score >= 300){
        
        metal = CCSprite::create("golden.png");
        metal->setScale(4);
        metal->setOpacity(0);
        metal->setPosition(ccp(213, 563));
        this->addChild(metal, 3);
        
        metal->runAction(CCSequence::create(CCDelayTime::create(1),
                                            CCFadeTo::create(0.1f, 255),
                                            CCEaseElasticOut::create(CCScaleTo::create(0.3, 1)),
                                            CCCallFuncN::create(this, callfuncN_selector(GameLayer::starOverAction)),
                                            NULL)
                         );
    }else if(score >= 200){
        
        metal = CCSprite::create("silver.png");
        metal->setScale(4);
        metal->setOpacity(0);
        metal->setPosition(ccp(213, 563));
        this->addChild(metal, 3);
        
        metal->runAction(CCSequence::create(CCDelayTime::create(1),
                                            CCFadeTo::create(0.1f, 255),
                                            CCEaseElasticOut::create(CCScaleTo::create(0.3, 1)),
                                            CCCallFuncN::create(this, callfuncN_selector(GameLayer::starOverAction)),
                                            NULL)
                         );
        
    }else if(score >= 100){
        
        metal = CCSprite::create("copper.png");
        metal->setScale(4);
        metal->setOpacity(0);
        metal->setPosition(ccp(213, 563));
        this->addChild(metal, 3);
        
        metal->runAction(CCSequence::create(CCDelayTime::create(1),
                                            CCFadeTo::create(0.1f, 255),
                                            CCEaseElasticOut::create(CCScaleTo::create(0.3, 1)),
                                            CCCallFuncN::create(this, callfuncN_selector(GameLayer::starOverAction)),
                                            NULL)
                         );
    }
}

void GameLayer::starOverAction(CCNode* pSender){
    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("goldDwon.mp3");

    CCParticleSystem *system = CCParticleSystemQuad::create("start.plist");
    system->setPosition(ccp(215, 576));
    this->addChild(system, 2);
}

void GameLayer::shareAction(CCNode* pSender){
    CCActionInterval*  actionTo = CCScaleBy::create(1, 1.05, 0.95);
    CCFiniteTimeAction*  seqAction1 = CCSequence::create( actionTo, actionTo->reverse(), NULL);
    
    CCActionInterval*  moveBy = CCMoveBy::create(1, ccp(0, -15));
    CCFiniteTimeAction*  seqAction = CCSequence::create( moveBy, moveBy->reverse(), NULL);
    
    itemShare->runAction(CCRepeatForever::create(
                                                CCSpawn::create(seqAction1,
                                                                seqAction,
                                                                NULL)
                                                )
                        );

}

void GameLayer::buttonM(){
    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("panel.mp3");
}